package com.vdf.sisconsolid.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.NamingException;

public class DatabaseResource {
	static private Connection conn = null;
	public static Connection getConnection() {
		try {
//			Context initContext = new InitialContext();
//			Context envContext  = (Context)initContext.lookup("java:/comp/env");
//			DataSource ds = (DataSource)envContext.lookup("jdbc/SisconsolidDataSource");
//			conn = ds.getConnection();
			
		    conn =
		       DriverManager.getConnection("jdbc:mysql://localhost/sisconsolid?" +
		                                   "user=root&password=admin");

		    
		} catch (SQLException ex) {
		    // handle any errors
		    System.out.println("SQLException: " + ex.getMessage());
		    System.out.println("SQLState: " + ex.getSQLState());
		    System.out.println("VendorError: " + ex.getErrorCode());
		} /*catch (NamingException e) {
			e.printStackTrace();
		}*/
		return conn;
	}
	
	public static boolean closeConnection() {
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return true;
	}

}
